package com.api.aiyh_pcn.copy_attachment.web;


import aiyh.utils.ApiResult;
import aiyh.utils.zwl.common.ToolUtil;
import com.api.aiyh_pcn.copy_attachment.service.CopyAttachmentService;
import com.api.aiyh_pcn.copy_attachment.dao.ConfigTableData;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.Map;

/**
 * @author EBU7-dev1-ayh
 * @create 2021/8/26 0026 10:16
 * copy ttachment to workflow
 */


@Path("/copyAttachment")
public class CopyAttachment {
	
	ToolUtil toolUtil = new ToolUtil();

	@POST
	@Path("/copy")
	@Consumes(MediaType.APPLICATION_JSON)
	@Produces(MediaType.APPLICATION_JSON)
	public String copyAttachment(@Context HttpServletRequest request, @Context HttpServletResponse response,
	                             @RequestBody Map<String, Object> params) {
		this.toolUtil.writeDebuggerLog("文件拷贝，接收参数：" + params);
		User user = HrmUserVarify.getUser(request, response);
		return CopyAttachmentService.copyFile(user,params);
	}

	@Path("/deleteFile/{docIds}")
	@GET
	@Consumes(MediaType.APPLICATION_JSON)
	@Produces(MediaType.APPLICATION_JSON)
	public String deleteFile(@Context HttpServletRequest request, @Context HttpServletResponse response,
	                         @PathParam("docIds") String docIds) {
		this.toolUtil.writeDebuggerLog("文件删除，接收参数：" + docIds);
		return CopyAttachmentService.deleteFile(docIds);
	}

	@Path("/queryConfig/{workflowId}")
	@GET
	@Consumes(MediaType.APPLICATION_JSON)
	@Produces(MediaType.APPLICATION_JSON)
	public String queryConfig(@PathParam("workflowId") String workflowId) {
		this.toolUtil.writeDebuggerLog("获取配置参数，接收参数为： " + workflowId);
		return ApiResult.success(ConfigTableData.getConfig(workflowId));
	}

	@Path("/queryFilesData")
	@POST
	@Consumes(MediaType.APPLICATION_JSON)
	@Produces(MediaType.APPLICATION_JSON)
	public String queryFilesData(@Context HttpServletRequest request, @Context HttpServletResponse response,
	                             @RequestBody Map<String, Object> params){
		this.toolUtil.writeDebuggerLog("查看文件信息，接收参数：" + params);
		User user = HrmUserVarify.getUser(request, response);
		return CopyAttachmentService.queryFilesData(user, params);
	}
}
